﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;


namespace Common
{
    public class SeriAndDeseri
    {

        public static Stream SerializeMultipleObjects(PlainText pt)
        {
            // Initialize a storage medium to hold the serialized object
            Stream stream = new MemoryStream();

            // Serialize an object into the storage medium referenced by 'stream' object.
            BinaryFormatter formatter = new BinaryFormatter();

            // Serialize multiple objects into the stream
            formatter.Serialize(stream, pt);

            // Return a stream with multiple objects
            return stream;
        }

        public static PlainText DeSerializeMultipleObject(Stream stream)
        {
            // Construct a binary formatter
            BinaryFormatter formatter = new BinaryFormatter();

            // Deserialize the stream into object
            return (PlainText)formatter.Deserialize(stream);
        }
    }
}
